package com.qi.qipay.api.controllers;

import com.qi.qipay.commons.controller.BaseController;
import com.qi.qipay.commons.service.IService;
import com.qi.qipay.commons.service.ServiceContainer;
import com.qipay.service.i.IAppService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/app")
public class AppController extends BaseController {
    @PostMapping("/{servicePrefix}/{methodName}")
    @ResponseBody
    public Object doRequest(final HttpServletRequest request, final HttpServletResponse response,
                            @PathVariable("servicePrefix") String servicePrefix,
                            @PathVariable("methodName") String methodName) {
        return super.doRequest(request, response, servicePrefix, methodName);
    }

    @Override
    protected Object doing(String servicePrefix, String methodName, Map<String, Object> paramMap) throws Exception {

        return ServiceContainer.invokeService(IAppService.class, getServiceName(servicePrefix), methodName, paramMap);
    }

    @Override
    protected String getServiceName(String servicePrefix) {
        return servicePrefix + "AppService";
    }
}
